Previous topicNext topic
Help > Keyword Reference >
STR$ function

Purpose

Return the string representation of a number in printable form.

Syntax

s$ = STR$(numeric_expression [, digits])

Remarks

STR$ returns the string form of a numeric variable or expression in printable text form. digits is an optional integral expression specifying the maximum total number of digits to appear in the result. If numeric_expression is greater than or equal to zero, STR$ adds a leading space character; if numeric_expression is less than zero, STR$ adds a leading negation (minus) character.

For example, STR$(14) returns a three-character string, of which the first character is a space, and the second and third are the ASCII characters "1" and "4". LTRIM$ can be used to remove leading space characters.

digits specifies the maximum number of significant digits (1 to 18) desired in the result.

STR$ can also be used to convert numeric values with more than 16 significant digits (i.e., Extended-precision floating-point and Quad-integers) to a printable form. For example:

a## = 2.0/3.0

x$ = STR$(a##,18)

returns 0.666666666666666667.

The complementary function is VAL, which takes a string argument and returns the numeric equivalent. Thus, number = VAL(STR$(number)).

An integer-class numeric value may also be converted to a string with the FORMAT$ and USING$ functions; however, FORMAT$ can easily return a string that is free from leading space characters. For example, x$ = FORMAT$(a&).

See also

BIN$, FORMAT$, HEX$, LTRIM$, OCT$, ROUND, USING$, VAL

Example

x$ = STR$(-1,5)

x$ = STR$(5/3,2)

x$ = STR$(5/3,8)

x$ = STR$(100000## / 3##, 18)

Result

-1

1.7

1.6666667

33333.3333333333333